package org.noote.libs.virtualpad;

public class Virtual1DPad extends VirtualTouchPad {
	
	protected boolean _bPressed = false;
	
	protected boolean _bEnableLockMode = false;
	protected boolean _bLocked = false;
	protected String _sText = "";
	
	public Virtual1DPad()
	{
		super();
	}
	public Virtual1DPad(boolean bLock)
	{
		super();
		_bEnableLockMode = bLock;
	}

	public void setText(String sText)
	{
		_sText = sText;	
	}

	@Override
	protected void _checkButtons()
	{
		_bPressed = false;
		
		// if event is move => set a pressed
		if(_iState == TOUCH_MOVED) _iState = TOUCH_PRESSED;
		
		// pressed or released touch ?
		if((_iState == TOUCH_RELEASED && _iOldState == TOUCH_PRESSED)
				|| (_iOldState == TOUCH_RELEASED && _iState == TOUCH_PRESSED))
			_bNewEvent = true;
		
		// is in button ?
		if(_iState == TOUCH_PRESSED)
		{
			float fLimitMin = -0.85f;
			float fLimitMax = 0.85f;
			
			if(_fPosition_X>=fLimitMin && _fPosition_X<=fLimitMax
				&& _fPosition_Y>=fLimitMin && _fPosition_Y<=fLimitMax)
			{
				_bPressed = true;
			}
		}
		// lock mode
		if(_bEnableLockMode)
		{
			// lock/unlock :)
			if(_iOldState == TOUCH_RELEASED && _iState == TOUCH_PRESSED)
				_bLocked = !_bLocked;
		}
	}

	// can locking
	public void enableLock(boolean bLock){_bEnableLockMode = bLock;}
	public boolean isLockable(){return _bEnableLockMode;}	
	
	// set lock
	public void setLock(boolean bLock){_bLocked = bLock;}
	public boolean isLocked(){return _bLocked;}
	
	// get button ?
	public boolean getButton(){return _bPressed;}
}
